//
//  KVNConsultantTableViewCell.m
//  Test1
//
//  Created by KelvinYeung on 15/8/9.
//  Copyright (c) 2015年 KelvinYeung. All rights reserved.
//

#import "KVNConsultantTableViewCell.h"

@implementation KVNConsultantTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    [self initSubviews];
    return self;

}

- (void) initSubviews{

    _avatarImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:_avatarImageView];
    [_avatarImageView setImage:[UIImage imageNamed:@"account"]];
    _avatarImageView.layer.cornerRadius = 30;
    _avatarImageView.layer.borderColor = [[UIColor colorWithWhite:0.9 alpha:1] CGColor];
    _avatarImageView.layer.borderWidth = 0.5;
    _avatarImageView.clipsToBounds = YES;
    _avatarImageView.translatesAutoresizingMaskIntoConstraints = NO;
    
    _userNameLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_userNameLabel];
    _userNameLabel.textColor = [UIColor grayColor];
    _userNameLabel.translatesAutoresizingMaskIntoConstraints = NO;
    
    _commentStarView = [[KVNCommentStarView alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    _commentStarView.startSize = 20;
    [self.contentView addSubview:_commentStarView];
    _commentStarView.translatesAutoresizingMaskIntoConstraints = NO;
    
    _commentContentLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_commentContentLabel];
    _commentContentLabel.textColor = [UIColor grayColor];
    _commentContentLabel.translatesAutoresizingMaskIntoConstraints = NO;
    
    _telButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.contentView addSubview:_telButton];
    [_telButton setTintColor:[UIColor redColor]];
    [_telButton setImage:[UIImage imageNamed:@"index_btnbg_call_white"] forState:UIControlStateNormal];
    _telButton.translatesAutoresizingMaskIntoConstraints = NO;
    
    _imButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.contentView addSubview:_imButton];
    _imButton.tintColor = [UIColor redColor];
    [_imButton setImage:[UIImage imageNamed:@"index_btnbg_chat_white"] forState:UIControlStateNormal];
    _imButton.translatesAutoresizingMaskIntoConstraints = NO;

    UILabel *telButtonLabel = [[UILabel alloc]init];
    UILabel *imButtonLabel = [[UILabel alloc]init];
    [self.contentView addSubview:telButtonLabel];
    [self.contentView addSubview:imButtonLabel];
    
    telButtonLabel.text = @"打电话";
    imButtonLabel.text = @"在线咨询";
    telButtonLabel.textColor = [UIColor grayColor];
    imButtonLabel.textColor = [UIColor grayColor];
    telButtonLabel.font = [UIFont systemFontOfSize:14];
    imButtonLabel.font = [UIFont systemFontOfSize:14];
    
    telButtonLabel.translatesAutoresizingMaskIntoConstraints = NO;
    imButtonLabel.translatesAutoresizingMaskIntoConstraints = NO;
    
    
    
    //layout
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_avatarImageView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1 constant:10]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_avatarImageView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1 constant:10]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_avatarImageView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:60]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_avatarImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:60]];
    
    
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_userNameLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1 constant:10]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_userNameLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:_avatarImageView attribute:NSLayoutAttributeRight multiplier:1 constant:15]];
    
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_commentStarView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_userNameLabel attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_commentStarView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:_avatarImageView attribute:NSLayoutAttributeRight multiplier:1 constant:15]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_commentStarView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:25]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_commentStarView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:100]];
    
    
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_commentContentLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_commentStarView attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_commentContentLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:_avatarImageView attribute:NSLayoutAttributeRight multiplier:1 constant:15]];
    
    
    
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_imButton attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1 constant:-10]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_imButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1 constant:10]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_imButton attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:50]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_imButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:50]];
    
    
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_telButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1 constant:10]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_telButton attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:_imButton attribute:NSLayoutAttributeLeft multiplier:1 constant:-25]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_telButton attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:50]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_telButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:50]];
    
    
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:telButtonLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_telButton attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:telButtonLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:_telButton attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:imButtonLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_imButton attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:imButtonLabel attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:_imButton attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
    
    
    

}


@end
